import request from "@/utils/request";

export interface ArticleQuery extends PageQuery {
  page?: number;
  limit?: number;
  sort?: string;
  keywords?: string;
}

export interface ArticleDetail {
  id: number;
  category_id: number;
  shop_id: number;
  shop_title: string;
  title: string;
  subtitle: string;
  status: number;
  sort: number;
  content?: string;
  thumb?: string;
}


export interface ArticleForm {
  id?: number;
  category_id?: number;
  shop_id?: number;
  title?: string;
  subtitle?: string;
  content?: string;
  summary?: string;
  thumb?: string;
  status?: number;
  sort?: number;
}

const baseUri = "/mv1/api/article/";

export function getArticleList(query: ArticleQuery) {
  return request({
    url: baseUri,
    method: "get",
    params: query,
  });
}

export function getArticleDetail(id: number) {
  return request({
    url: baseUri + "detail/" + id,
    method: "get",
    params: {},
  });
}

export function createArticle(data: ArticleForm) {
  return request({
    url: baseUri + "create",
    method: "post",
    data,
  });
}

export function updateArticle(id: number, data: ArticleForm) {
  return request({
    url: baseUri + "edit/" + id,
    method: "put",
    data,
  });
}

export function deleteArticle(id: number) {
  return request({
    url: baseUri + id,
    method: "delete",
    data: {},
  });
}
